#!/usr/bin/env python
"""
    This file is part of Athedyn's Tale.

    Athedyn's Tale is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Athedyn's Tale is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Athedyn's Tale.  If not, see <http://www.gnu.org/licenses/>.
"""

from rpg import *
import thread

global currentArea

db = Database()
main = Main()
enemy = Enemy()
area = Area()
job = Jobs()
commands = Commands()
item = Items()
attack = Attack()
aCommands = ACommands()
magic = Magic()
quest = Quest()
shop = Shop(db)

user = main.load()
if user == 0:
    user = User()
    statistics = job.chose(item)
    user.new(statistics)
else:
    pass

objects = {'main': main, 'enemy': enemy, 'area': area, 'job': job, 'user': user, 'commands': commands, 'items': item, 'attack': attack, 'aCommands': aCommands, 'magic': magic, 'quest': quest, 'shop': shop}

for key, obj in objects.items():
    obj.setObjects(objects)

area.commandSetup()
attack.commandSetup()
user.setUpMap()

thread.start_new(user.regen, ())

area.readStats(user.statistics['zone'])
user.setUpItems()
area.setUpItems()
user.setUpQuest()
area.new(user.statistics['lastArea'], 0)

while area.Continue:
    Continue, enemyID = area.moveArea()
    if enemyID > 0:
        enemy.new(enemyID)
        attack.attack()
        if user.statistics['health'] <= 0:
            print "Please try again."
            area.Continue = 0
            break
        area.printDescription()
    
print "Goodbye!"
time.sleep(2)
